$(function(){
    initData();//加载界面中需要的数据
});

/*********************************************服务整体情况tab页数据加载***************************************************/

//服务整体评分折线图
function initData(){
    var echart = echarts.init(document.getElementById("fwtjazt"));
    var dataMap = {};
    function dataFormatter(obj) {
        var pList = ['MES','HR','QQ','BL','SCM','SRM',
            'SRM2','MDM','DMS','OPC'];
        var temp;
        for (var year = 2002; year <= 2011; year++) {
            var max = 0;
            var sum = 0;
            temp = obj[year];
            for (var i = 0, l = temp.length; i < l; i++) {
                max = Math.max(max, temp[i]);
                sum += temp[i];
                obj[year][i] = {
                    name : pList[i],
                    value : temp[i]
                }
            }
            obj[year + 'max'] = Math.floor(max / 100) * 100;
            obj[year + 'sum'] = sum;
        }
        return obj;
    }

    dataMap.dataPI = dataFormatter({
        //max : 4000,
        2011:[136.27,159.72,2905.73,641.42,1306.3,
            1915.57,1277.44,1701.5,124.94,3064.78],
        2010:[124.36,145.58,2562.81,554.48,1095.28,1631.08,1050.15,1302.9,114.15,2540.1],
        2009:[118.29,128.85,2207.34,477.59,929.6,1414.9,980.57,1154.33,113.82,2261.86],
        2008:[112.83,122.58,2034.59,313.58,907.95,1302.02,916.72,1088.94,111.8,2100.11],
        2007:[101.26,110.19,1804.72,311.97,762.1,1133.42,783.8,915.38,101.84,1816.31],
        2006:[88.8,103.35,1461.81,276.77,634.94,939.43,672.76,750.14,93.81,1545.05],
        2005:[88.68,112.38,1400,262.42,589.56,882.41,625.61,684.6,90.26,1461.51],
        2004:[87.36,105.28,1370.43,276.3,522.8,798.43,568.69,605.79,83.45,1367.58],
        2003:[84.11,89.91,1064.05,215.19,420.1,615.8,488.23,504.8,81.02,1162.45],
        2002:[82.44,84.21,956.84,197.8,374.69,
            590.2,446.17,474.2,79.68,1110.44]
    });

    dataMap.dataSI = dataFormatter({
        //max : 26600,
        2011:[3752.48,5928.32,13126.86,6635.26,8037.69,12152.15,5611.48,5962.41,7927.89,25203.28],
        2010:[3388.38,4840.23,10707.68,5234,6367.69,9976.82,4506.31,5025.15,7218.32,21753.93,14297.93],
        2009:[2855.55,3987.84,8959.83,3993.8,5114,7906.34,3541.92,4060.72,6001.78,18566.37,11908.49],
        2008:[2626.41,3709.78,8701.34,4242.36,4376.19,7158.84,3097.12,4319.75,6085.84,16993.34,11567.42],
        2007:[2509.4,2892.53,7201.88,3454.49,3193.67,5544.14,2475.45,3695.58,5571.06,14471.26,10154.25],
        2006:[2191.43,2457.08,6110.43,2755.66,2374.96,4566.83,1915.29,3365.31,4969.95,12282.89,8511.51],
        2005:[2026.51,2135.07,5271.57,2357.04,1773.21,3869.4,1580.83,2971.68,4381.2,10524.96,7164.75],
        2004:[1853.58,1685.93,4301.73,1919.4,1248.27,3061.62,1329.68,2487.04,3892.12,8437.99,6250.38],
        2003:[1487.15,1337.31,3417.56,1463.38,967.49,2898.89,1098.37,2084.7,3209.02,6787.11,5096.38],
        2002:[1249.99,1069.08,2911.69,1134.31,754.78,
            2609.85,943.49,1843.6,2622.45,5604.49]
    });

    dataMap.dataTI = dataFormatter({
        //max : 25000,
        2011:[12363.18,5219.24,8483.17,3960.87,5015.89,8158.98,3679.91,4918.09,11142.86,20842.21],
        2010:[10600.84,4238.65,7123.77,3412.38,4209.03,6849.37,3111.12,4040.55,9833.51,17131.45],
        2009:[9179.19,3405.16,6068.31,2886.92,3696.65,5891.25,2756.26,3371.95,8930.85,13629.07],
        2008:[8375.76,2886.65,5276.04,2759.46,3212.06,5207.72,2412.26,2905.68,7872.23,11888.53],
        2007:[7236.15,2250.04,4600.72,2257.99,2467.41,4486.74,2025.44,2493.04,6821.11,9730.91],
        2006:[5837.55,1902.31,3895.36,1846.18,1934.35,3798.26,1687.07,2096.35,5508.48,7914.11],
        2005:[4854.33,1658.19,3340.54,1611.07,1542.26,3295.45,1413.83,1857.42,4776.2,6612.22],
        2004:[4092.27,1319.76,2805.47,1375.67,1270,2811.95,1223.64,1657.77,4097.26,5198.03],
        2003:[3435.95,1150.81,2439.68,1176.65,1000.79,2487.85,1075.48,1467.9,3404.19,4493.31],
        2002:[2982.57,997.47,2149.75,992.69,811.47,
            2258.17,958.88,1319.4,3038.9,3891.92]
    });

    dataMap.dataEstate = dataFormatter({
        //max : 3600,
        2011:[1074.93,411.46,918.02,224.91,384.76,876.12,238.61,492.1,1019.68,2747.89],
        2010:[1006.52,377.59,697.79,192,309.25,733.37,212.32,391.89,1002.5,2600.95,1618.17],
        2009:[1062.47,308.73,612.4,173.31,286.65,605.27,200.14,301.18,1237.56,2025.39,1316.84],
        2008:[844.59,227.88,513.81,166.04,273.3,500.81,182.7,244.47,939.34,1626.13,1052.03],
        2007:[821.5,183.44,467.97,134.12,191.01,410.43,153.03,225.81,958.06,1365.71,981.42],
        2006:[658.3,156.64,397.14,117.01,136.5,318.54,131.01,194.7,773.61,1017.91,794.41],
        2005:[493.73,122.67,330.87,106,98.75,256.77,112.29,163.34,715.97,799.73,688.86],
        2004:[436.11,106.14,231.08,95.1,73.81,203.1,97.93,137.74,666.3,534.17,587.83],
        2003:[341.88,92.31,185.19,78.73,61.05,188.49,91.99,127.2,487.82,447.47],
        2002:[298.02,73.04,140.89,65.83,51.48,
            130.94,76.11,118.7,384.86,371.09]
    });

    dataMap.dataFinancial = dataFormatter({
        //max : 3200,
        2011:[2215.41,756.5,746.01,519.32,447.46,
            755.57,207.65,370.78,2277.4],
        2010:[1863.61,572.99,615.42,448.3,346.44,
            639.27,190.12,304.59,1950.96],
        2009:[1603.63,461.2,525.67,361.64,291.1,
            560.2,180.83,227.54,1804.28],
        2008:[1519.19,368.1,420.74,290.91,219.09,
            455.07,147.24,177.43,1414.21],
        2007:[1302.77,288.17,347.65,218.73,148.3,
            386.34,126.03,155.48,1209.08],
        2006:[982.37,186.87,284.04,169.63,108.21,
            303.41,100.75,74.17,825.2],
        2005:[840.2,147.4,213.47,135.07,72.52,
            232.85,83.63,35.03,675.12],
        2004:[713.79,136.97,209.1,110.29,55.89,
            188.04,77.17,32.2,612.45],
        2003:[635.56,112.79,199.87,118.48,55.89,
            145.38,73.15,32.2,517.97],
        2002:[561.91,76.86,179.6,124.1,48.39,
            137.18,75.45,31.6,485.25,368.86]
    });


    option = {
        baseOption: {
            timeline: {
                axisType: 'category',
                data: [
                    '2009-01-01','2010-01-01','2011-01-01','2012-01-01',
                    '2013-01-01', '20014-01-01','2015-01-01','2016-01-01','2017-01-01',
                    '2018-01-01'
                ],
                label: {
                    formatter : function(s) {
                        return (new Date(s)).getFullYear();
                    }
                }
            },
            tooltip: {
            },
            legend: {
                x: 'center',
                top: 20,
                data: ['创建中', '待发布', '已发布', '挂起', '停用'],
            },
            calculable : true,
            grid: {
                top: 80,
                bottom: 100,
                tooltip: {
                    trigger: 'axis',
                    axisPointer: {
                        type: 'shadow',
                        label: {
                            show: true,
                            formatter: function (params) {
                                return params.value.replace('\n', '');
                            }
                        }
                    }
                }
            },
            xAxis: [
                {
                    'type':'category',
                    'axisLabel':{'interval':0},
                    'data':[
                        'MES','\HR','QQ','\BL','SCM',
                        '\SRM','SRM2','\MDM','DMS','\OPC'
                    ],
                    splitLine: {show: false}
                }
            ],
            yAxis: [
                {
                    type: 'value'
                }
            ],
            series: [
                {name: '挂起', type: 'bar'},
                {name: '停用', type: 'bar'},
                {name: '创建中', type: 'bar'},
                {name: '待发布', type: 'bar'},
                {name: '已发布', type: 'bar'},
                {
                    name: 'GDP占比',
                    type: 'pie',
                    center: ['75%', '35%'],
                    radius: '28%',
                    z: 100
                }
            ]
        },
        options: [
            {
                series: [
                    {data: dataMap.dataFinancial['2009']},
                    {data: dataMap.dataEstate['2009']},
                    {data: dataMap.dataPI['2009']},
                    {data: dataMap.dataSI['2009']},
                    {data: dataMap.dataTI['2009']},
                    {data: [
                            {name: '创建中', value: dataMap.dataPI['2009sum']},
                            {name: '待发布', value: dataMap.dataSI['2009sum']},
                            {name: '已发布', value: dataMap.dataTI['2009sum']},
                            {name: '挂起', value: dataMap.dataFinancial['2009sum']},
                            {name: '停用', value: dataMap.dataEstate['2009sum']}
                        ]}
                ]
            }
        ]
    };
    echart.setOption(option);
    echart.hideLoading();
    //自动适应屏幕浏览器的大小 当浏览器大小改变时 报表画布也跟着改变
    window.onresize = function () {
        echart.resize();
    };
}

/**********************************************************************************************************************/

function checkIsNull(val){
    if("undefined"!==val&&undefined!==val&&""!==val&&"null"!==val&&null!==val){
        return false;
    }else{
        return true;
    }
}

function backShuZiL(str){
    if(checkIsNull(str)){
        return 0;
    }else{
        return str;
    }
}

